package jfuzzyprincepless.zarchive.negotiation.protocols;

public class TypeFilter implements IFilter {
	private Class<?> clazz;
	private boolean wholeHierarhy;

	public TypeFilter(Class<?> clazz, boolean wholeHierarhy) {
		this.clazz = clazz;
		this.wholeHierarhy = wholeHierarhy;
	}

	public TypeFilter(Class<?> clazz) {
		this(clazz, false);
	}

	@Override
	public boolean accepts(Object obj) {
		if (wholeHierarhy) {
			return clazz.isAssignableFrom(obj.getClass());
		} else {
			return obj.getClass().equals(clazz);
		}
	}
}
